﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using Rodunu.Business.Models.Movies;

namespace Rodunu.Clients.WPF.Collection.Forms
{
    /// <summary>
    /// Interaction logic for DetailsForm.xaml
    /// </summary>
    public partial class DetailsForm : UserControl
    {
        public Title Movie
        {
            get
            {
                return (Title)DetailsGrid.DataContext;
            }
            set
            {
                DetailsGrid.DataContext = value;
            }
        }

        public DetailsForm()
        {
            InitializeComponent();

            DetailsGrid.DataContextChanged += DetailsGrid_DataContextChanged;
        }

        void DetailsGrid_DataContextChanged(object sender, DependencyPropertyChangedEventArgs e)
        {
            var newTitle = (Title) e.NewValue;
            if (newTitle.Directors.Count > 0)
            {
                foreach (var director in newTitle.Directors)
                {
                    if (DirectorsTextBox.Text.Length > 0)
                        DirectorsTextBox.Text += "; ";
                    DirectorsTextBox.Text += director.Name;
                }
            }
            if (newTitle.Genres.Count > 0)
            {
                foreach (var genre in newTitle.Genres)
                {
                    if (GenresTextBox.Text.Length > 0)
                        GenresTextBox.Text += "; ";
                    GenresTextBox.Text += genre;
                }
            }
        }
    }
}
